<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        合同电梯信息
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }

        /* layui-table 表格内容允许换行 */
        .layui-table-cell {
            height: auto;
        }

        .layui-btn+.layui-btn {
            margin-left: 0px !important;
        }

    </style>
</head>

<body>

    <div class="x-body" id="app" >
        <div class="layui-card-body" >
            <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>批量上传</button>
            <a onclick="uploadModelFile();">模板下载</a>
            <table class="layui-table" id="test" lay-filter="test">
            </table>
        </div>
    </div>
</body>

<script type="text/html" id="barDemo">

    <a title="删除" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">
        <i class="layui-icon">&#xe640;</i>
    </a>
</script>


<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script type="text/javascript" src="../../../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>


<script>

    var contractId = getQueryVariable("contractId");

    layui.use(['table','upload', 'element', 'laypage', 'layer', 'form', 'laytpl'], function () {
        $ = layui.jquery;//jquery
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        laytpl = layui.laytpl;
        upload = layui.upload;
        var table = layui.table;
        var form = layui.form;
        okLoading.close($);

        //方法级渲染
        var t1 = table.render({
            elem: '#test',
            url: $baseUrl + 'xa/contractElevator/findProjectElevatorList',
            where: {
                userId: $userId,
                contractId: contractId
            },
            headers: {
                token: $token
            }
            // , toolbar: '#toolbarDemo'

            // toolbar: true,
            , cols: [
                [
                    {
                        title: '序号',
                        type:'numbers',
                        width: '8%',
                        fixed: 'left',
                    },
                    {
                        field: 'elevatorNum',
                        title: '梯号',
                        align: 'center',
                        // templet(item) {
                        //     if (item.contractNature === 1) {
                        //         return '<button type="button" class="layui-btn layui-btn-xs layui-btn layui-btn-xs layui-btn-radius layui-btn">收款</button>';
                        //     } else if (item.contractNature === 2) {
                        //         return '<button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-warm">付款</button>';
                        //     }else {
                        //         return '<button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-danger">未知</button>';
                        //     }
                        //
                        // }
                    },
                    {
                        field: 'elevatorBrand',
                        title: '品牌',
                        align: 'center',
                    },
                    {
                        field: 'elevatorModel',
                        title: '型号',
                        align: 'center',
                    },
                    {
                        field: 'elevatorType',
                        title: '类型',
                        align: 'center',
                    },
                    {
                        field: 'elevatorLandingSpan',
                        title: '层站/跨度',
                        align: 'center',
                    },
                    {
                        field: 'elevatorLoad',
                        title: '载重（kg）',
                        align: 'center',
                    },
                    {
                        field: 'elevatorSpeed',
                        title: '速度(m/s)',
                        align: 'center',
                    },
                    {
                        field: 'elevatorPrice',
                        title: '设备单价(万)',
                        align: 'center',
                    },
                    {
                        field: 'freightPrice',
                        title: '运费单价（元）',
                        align: 'center',
                    },
                    {
                        field: 'installPrice',
                        title: '安装单价（元）',
                        align: 'center',
                    },
                    {
                        // field: 'status',
                        title: '操作',
                        templet: '#barDemo',
                        width: '6%',
                        fixed: 'right',
                        align: 'center',

                    }]
            ],
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                ,
                statusCode: 0 //规定成功的状态码，默认：0
                ,
                msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,
                countName: 'total' //规定数据总数的字段名称，默认：count
                ,
                dataName: 'data', //规定数据列表的字段名称，默认：data
            },
            id: 'test',
            page: false,
            limit: Number.MAX_VALUE,
            height: 'auto',
            even: true,
            done: function (res, curr, count) {
                //是否有权限或权限是否失效
                // authorizeState();
                // this.statisticsFun();
                //解决操作栏因为内容过多换行问题
                $(".layui-table-main tr").each(function (index, val) {
                    $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
                    $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
                });

            }
        });

        //指定允许上传的文件类型
        var index = null;
        upload.render({
            elem: '#test3'
            ,url:baseHead + "/xa/contractElevator/importContractElevatorExcel"//改成您自己的上传接口
            ,headers: {
                "token": $token,
            }
            ,data: {
                userId: $userId,
                contractId:contractId
            }
            ,accept: 'file' //普通文件
            ,choose:function (obj) {
                index = layer.load(1); //换了种风格

            }
            ,done: function(res){

                layer.close(index);
                t1.reload();
                if (res.code === 0) {

                        layer.msg("批量添加成功", {
                            icon: 1
                        });
                        t1.reload();

                } else {
                    layer.alert(res.msg, {
                        icon: 2
                    });
                }
            }
        });


        //监听工具条
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'del') { //删除
                layer.confirm('是否确认删除 ？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let request = {
                        url: "xa/contractElevator/delById/" + data.id,
                        data: {
                            userId: $userId,
                        },
                        method: "DELETE",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.msg("删除成功", {
                                icon: 1
                            });
                            t1.reload();
                        } else {
                            layer.msg("删除失败，请稍后再试！", {
                                icon: 5
                            });
                        }
                    });
                    layer.close(index);
                });
            }
        });

    });

    function reload(value) {
        table.reload('test', {
            where: {

            }
        });
    }
    function uploadModelFile() {
        window.location.href = baseHead+"template_file/elevator_info.xlsx";
    }
    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }
</script>
</html>
